package com.quark.controller.system;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.quark.result.Asserts;
import com.quark.result.RequestResult;
import com.quark.service.system.RoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张高昌
 * @version 版本
 * @date 2021/11/11 16:09
 * @description: 角色权限管理
 */
@Api(tags = "角色权限管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/roleMenu")
public class RoleMenuController {

    private final RoleMenuService roleMenuService;

    @ApiOperation("修改菜单")
    @PostMapping("authorize/{rId}")
    public RequestResult authorize(@PathVariable("rId") String rId, @RequestBody String rules) {
        if (StrUtil.isBlankIfStr(rId)) {
            Asserts.fail("rId不能为空！");
        }
        if (StrUtil.isBlankIfStr(rules)) {
            Asserts.fail("菜单不能为空！");
        }
        JSONObject jsonObject = JSONUtil.parseObj(rules);
        String rules1 = jsonObject.getStr("rules");

        return RequestResult.success(roleMenuService.authorize(Integer.valueOf(rId), rules1));
    }

}
